<?php

class Order extends Admin_Controller {

    function Order() {
        parent::Admin_Controller();
        $this->load->model('Order_m');
    }

    function index() {
        $this->list_order();
    }

    function list_order() {
        is_admin();
        $this->_data['page_title'] = "Ordre de la liste";
        $per_page = $this->uri->segment(3);
        $offset = $this->uri->segment(4);
        if ($per_page == "") {
            $per_page = 10;
        }
        if ($offset == "") {
            $offset = 0;
        }
        $config['base_url'] = base_url() . 'index.php/order/list_order/' . $per_page . '/';
        $config['per_page'] = '10';
        $config['uri_segment'] = 4;
        $config['total_rows'] = $this->db->count_all('commande');

        $config['full_tag_open'] = "<div id='containpage'>";
        $config['full_tag_close'] = '</div>';
        $config['cur_tag_open'] = '<span id="pageactive"> ';
        $config['cur_tag_close'] = ' </span>';
        $config['next_link'] = '&gt;&gt;';
        $config['prev_link'] = '&lt;&lt;';

        if ($config['total_rows'] == $offset)
            $offset = $offset - $per_page;
        $this->_data['perpage'] = $config['per_page'];
        $this->_data['offset'] = $offset;

        $this->_data['query'] = $this->Order_m->get_all_order($config['per_page'], $offset);
        $this->pagination->initialize($config);
        $this->_data['pagination'] = $this->pagination->create_links();
        $this->_data['total'] = $this->db->count_all('commande');
        $this->display_view('order/order');
    }

    function detail_order($id) {
        is_admin();
        $this->_data['page_title'] = "Afin de détails";
        $this->_data['order'] = $this->Order_m->get_order($id);
        $this->_data['detail_order'] = $this->Order_m->get_detail_order($id);
        $this->display_view('order/detail_order');
    }

    function delete_order($id, $perpage, $offset) {
        is_admin();
        $query = $this->Order_m->delete_order($id);
        if ($query == 1)
            redirect(site_url('order/list_order' . '/' . $perpage . '/' . $offset));
    }

    function update_date_livraison($id, $perpage, $offset) {
        is_admin();
        $this->_data['page_title'] = "mise à jour date de Livraison";
        $query = $this->Order_m->update_date_livraison($id);
        if ($query == 1)
            redirect(site_url('order/list_order' . '/' . $perpage . '/' . $offset));
    }

    function update_date_livraison_detail($id) {
        is_admin();
        $this->_data['page_title'] = "mise à jour les informations sur delivery date";
        $query = $this->Order_m->update_date_livraison($id);
        if ($query == 1)
            redirect(site_url('order/detail_order' . '/' . $id));
    }

}

?>